package org.feng.service;

import org.feng.datasource.DataSourceConstant;
import org.feng.datasource.ExchangeDataSource;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Map;

/**
 * 测试切换数据源
 *
 * @version v1.0
 * @author: fengjinsong
 * @date: 2022年05月06日 10时33分
 */
@EnableAspectJAutoProxy(proxyTargetClass = true)
@Service
public class TestServiceImpl implements Test {

    @Resource
    private JdbcTemplate jdbcTemplate;

    @Override
    @ExchangeDataSource
    public Map<String, Object> dbTestMaster() {
        return jdbcTemplate.queryForMap("select * from test");
    }

    @Override
    @ExchangeDataSource(DataSourceConstant.SLAVE1)
    public Map<String, Object> dbTestSlave1() {
        return jdbcTemplate.queryForMap("select * from test");
    }
}
